<template>
    <rx-layout>
        <div slot="left" width="250" showButton="true">
            <rx-fit>
                <rx-category-treeeditor
                    cat-key="SYSTEM"
                    :statisticConfig="statisticConfig"
                    :edit="true"
                    @handSelect="handSelect"
                    :async="true"
                ></rx-category-treeeditor>
            </rx-fit>
        </div>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="sysKettleDefAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{$ti18('rxList.add','新增')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="sysKettleDefEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="sysKettleDefDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.name','名称')">
                            <a-input :placeholder="i18n('form.name','名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysKettleDef/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="storeType" slot-scope="{ text, record }">
                        <span>{{storeMap[text]}}</span>
                    </span>
                    <span slot="type" slot-scope="{ text, record }">
                        <span>{{typeMap[text]}}</span>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click.stop="runKettle(record)">{{i18n('list.run','运行')}}</span>
                        <span @click="setKettleJob(record)" :title="i18n('list.taskSchedu','任务调度')">{{i18n('list.taskSchedu','任务调度')}}</span>
                        <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import SysKettleDefApi from '@/api/system/core/sysKettleDef'
import SysKettleDefEdit from './SysKettleDefEdit'
import SysKettleJobEdit from './SysKettleJobEdit'
import {BaseList, RxFit, RxGrid,Util} from "@lowcode/jpaas-common-lib";
import RxCategoryTreeeditor from "@/components/redxun/rx-category-treeeditor";

export default {
    name: 'SysKettleDefList',
    mixins: [BaseList],
    components: {
        RxFit,
        RxCategoryTreeeditor
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.name','名称'), dataIndex: 'name', width: 100},
                {title: this.i18n('form.storeType','存储类型'), dataIndex: 'storeType', width: 100, scopedSlots: {customRender: 'storeType'}},
                {title: this.i18n('form.type','类型'), dataIndex: 'type', width: 100, scopedSlots: {customRender: 'type'}},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: SysKettleDefEdit,
            comment: this.i18n('list.comment','KETTLE定义'),
            widthHeight: ['800px', '600px'],
            fitSearch: false,
            storeMap: {'database': this.i18n('form.database','资源库'), 'file':this.i18n('form.file','文件')},
            typeMap: {'job': this.i18n('form.job','作业'), 'transformation':this.i18n('form.transformation','转换')},
            statisticConfig: {
                type:"static_system",
                table:"SYS_KETTLE_DEF",
                field:"GATEGORY_",
                whereConf:[]
            }
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"SysKettleDef",key);
        },
        delById(ids) {
            return SysKettleDefApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return SysKettleDefApi.query(parameter)
        },
        handSelect(curRow) {
            this.curTree = curRow;
            this.loadData({Q_GATEGORY__S_EQ: curRow.treeId});
        },
        //运行
        runKettle(record){
            SysKettleDefApi.runKettle(record.id).then(res =>{
                var type=res.success?"success":"error";
                var msg=res.success?this.i18n('msa.success','成功'):this.i18n('msa.error','失败');
                var description=this.i18n('list.run','运行')+msg+"!";
                this.$notification[type]({
                    message: this.$ti18('rxMsa.actionTips','操作提示'),
                    description: description
                });
            });
        },
        setKettleJob(record){
            Util.open({
                component:SysKettleJobEdit,
                curVm:this,
                widthHeight:['1000px','700px'],
                title:this.i18n('list.taskScheduTitle','KETTLE任务调度'),
                data:{
                    kettleId:record.id
                }
            },function (action){});
        }

    }
}
</script>
<style scoped>

</style>

